Fix specular mapping with linear blend regime#1941
Fix specular mapping with linear blend regime#1941slipher wants to merge 1 commit intoDaemonEngine:for-0.56.0/syncfrom
Conversation
The default behavior was to convert specular maps from sRGB to linear colorspace when using the linear blend regime. But for most of our assets, doing sRGB conversion of specular maps (when in the linear blend regime) looks almost the same as disabling specular mapping, while loading them as-is looks fairly comparable to naive mode. So don't do the conversion.
|
Please keep the mechanism to switch the specular map colorspace, just revert the default. Specular maps from tex-ex need to be linearized, as seen on those walls, it is obviously wrong to load those specular maps the linear way: I'll add a sloth keyword to make Sloth add the related keyword to the shader. So we better configure some texture sets for one format. |
|
We probably have to load as sRGB all texture sets by evillair. The textures in chasm are by phillipk. |
|
So we may do:
We may also selectively convert textures from vega, but not all. |
|
Some documentation showing that there are mixed usage of linar and sRGB space for specular maps:
About that document I just quoted, it talks about specular maps and gloss maps, while Xonotic names specular maps gloss maps, in that document, gloss maps are rougness maps (for PBR). In this document it looks like what they call specular is what we call specular.
Here what's said on light on that last quote may be specific to that engine (basically doing like q3map2 -sRGB), but the specular map isn't supposed to be engine-specific.
Now this one contradicts the previous ones. The reason seems simple: early specular maps were likely done in authoring tools and for engines not caring about colorspace. But as time goes, workflows became corrected. The more in industry practics we come close to what will become PBR, the more we can expect linear specular maps. We can rephrase it: Textures used for retrieving lighting parameters should be in linear space. But it looks like the practice was different. |
|
For information in my early implementations of the linear pipeline, I was loading all specular maps in linear space. My first iterations of my sRGB testing server was loading all specular maps in linear space (like your branch does), but then based on feedback I switched them for loading as sRGB. |
|
This map makes obvious assuming that all specular maps are linear may be a bad idea: |
|
Here is a quote from a previous detailed comment of mine on the topic:
The document I linked at the time said:
In that document, the specular map is stored in sRGB space, only the factor is in linear space, which makes sense, we better not multiply an sRGB factor. As I said at the time in the other thread, we even have some of those RGBA specular maps, and I do believe they are specular+glossiness as the quote from our about page that says « Support […] gloss, specular […] maps » is very old (maybe even older than me contributing to Unvanquished). This sentence was reworded by me from time to time, but that gloss mention wasn't added by me. All I did was to carry that gloss mention over, sometime not knowing (yet) what it meant but observing a conservative approach in writing, just in case, to not lose the information that predated my efforts. |
What should the shader keywords be? Since the keywords were designed as a button that that can only be pushed one way, one must think of a new set of keywords when changing the default... |
|
I'm not sure this is a good idea to change the default. It looks like we're deciding to change the whole because of a single rock texture. |
|
As a remind, we switched to “sRGB specular map as default” after testing “linear specular map as default” and finding that “sRGB specular map as default” was statistically more correct with our corpus. Then we added keywords to allow us to switch that per-shader if such need surfaces. That rock may be a good candidate for that. |
Well I gave a second example from Chasm so hopefully it was at least because of a single texture set :) I checked a few of those station15 ones for consistency with the naive render and your conclusions seem reasonable. |
|
For the comparison in corridor, we should remind that the naive look cannot fully be used as a reference of correctness to begin with. Some of our textures even been designed for other game engines (like Unreal Engine for the tech set), and we may have been wrong with them from the start. Trying to reproduce the old look just for the sake of reproducing the old look may encourage us to introduce bugs. The pk02 rock looks better when assumed linear, but I'm not sure that's what to do with others from the same texture set. I shown this pk02 door on spacetracks: But we can also look that pk02 wall on spacetracks: Light reflection may be too strong. |
|
According to philipk.net, the pk01 and pk02 texture sets were done for idTech4. I wonder what iTech4 did, I even don't know if they did colorspace correction at all… |
|
More precisely, according to the readme in the zips, they were made for Quake IV. |
|
So I did some research, and it looks like id Tech 4 and Quake 4 were just doing it the naive way, using similar gamma ramp trick like Quake 3 at the end of the pipeline, so basically not linearizing any input. But then the PK texture packs themselves were never meant to be used as “all linear specular maps” or “all sRGB specular maps”, we may have to evaluate them per texture, not just per texture set. |
Hoping that it looks like another engine by just picking the colorspace is probably hopeless since there are a bunch of tunable parameters with specular exponent etc. and they are probably different. Though I think it is possible to customize those with shader keywords. For me the point of reference is just whether it looks like what the mapper saw when placing the texture in their map. |
|
In the end maybe we are just using the colorspace as a blunt instrument for making things brighter/dimmer, like the colorspace with colormaps that use blendfunc add. But at least with specular maps there are more tools to experiment with finer adjustments. |


















The default behavior was to convert specular maps from sRGB to linear colorspace when using the linear blend regime. But for most of our assets, doing sRGB conversion of specular maps (when in the linear blend regime) looks almost the same as disabling specular mapping, while loading them as-is looks fairly comparable to naive mode. So don't do the conversion.
Here are some screenshots, with tonemapping off for easier comparison, of the scene discussed at Unvanquished/Unvanquished#3446 (comment).
NAIVE (via r_forceBlendRegime)
LINEAR (before)
LINEAR (after)
The wall under the light here is a nice easy-to-see example:
NAIVE (via r_forceBlendRegime
LINEAR (before)
LINEAR (after)